<template>
    <el-dialog
            :title="!dataForm.orderId ? '新增' : '修改'"
            :close-on-click-modal="false"
            :visible.sync="visible">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
                            <el-form-item label="主键ID" prop="id">
                        <el-input v-model.number="dataForm.id" placeholder="主键ID"></el-input>
                </el-form-item>
                <el-form-item label="原始数据ID（关联数据采集表的id）" prop="originalDataId">
                        <el-input v-model.number="dataForm.originalDataId" placeholder="原始数据ID（关联数据采集表的id）"></el-input>
                </el-form-item>
                <el-form-item label="是否去重（TRUE为已去重，FALSE为未去重）" prop="isDeduplicated">
                        <el-input v-model="dataForm.isDeduplicated" placeholder="是否去重（TRUE为已去重，FALSE为未去重）"></el-input>
                </el-form-item>
                <el-form-item label="数据格式类型（如JSON、CSV等）" prop="formatType">
                        <el-input v-model="dataForm.formatType" placeholder="数据格式类型（如JSON、CSV等）"></el-input>
                </el-form-item>
                <el-form-item label="是否进行格式转换（TRUE为已转换，FALSE为未转换）" prop="formatConversion">
                        <el-input v-model="dataForm.formatConversion" placeholder="是否进行格式转换（TRUE为已转换，FALSE为未转换）"></el-input>
                </el-form-item>
                <el-form-item label="数据准确性（TRUE为准确，FALSE为不准确）" prop="accuracy">
                        <el-input v-model="dataForm.accuracy" placeholder="数据准确性（TRUE为准确，FALSE为不准确）"></el-input>
                </el-form-item>
                <el-form-item label="数据一致性（TRUE为一致，FALSE为不一致）" prop="consistency">
                        <el-input v-model="dataForm.consistency" placeholder="数据一致性（TRUE为一致，FALSE为不一致）"></el-input>
                </el-form-item>
                <el-form-item label="数据清洗时间" prop="cleaningTime">
                        <el-date-picker
                                v-model="dataForm.cleaningTime"
                                type="datetime"
                                placeholder="数据清洗时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="记录创建时间" prop="createTime">
                        <el-date-picker
                                v-model="dataForm.createTime"
                                type="datetime"
                                placeholder="记录创建时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="记录更新时间" prop="updateTime">
                        <el-date-picker
                                v-model="dataForm.updateTime"
                                type="datetime"
                                placeholder="记录更新时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="清洗后的数据内容" prop="cleanedData">
                        <el-input v-model="dataForm.cleanedData" placeholder="清洗后的数据内容"></el-input>
                </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
    </el-dialog>
</template>

<script>
    export default {
        data () {
            return {
                visible: false,
                dataForm: {
                    id: null,
                    originalDataId: null,
                    isDeduplicated: null,
                    formatType: null,
                    formatConversion: null,
                    accuracy: null,
                    consistency: null,
                    cleaningTime: null,
                    createTime: null,
                    updateTime: null,
                    cleanedData: null,
                },
                dataRule: {
                    id: [
                        { required: true, message: '主键ID不能为空', trigger: 'blur' }
                    ],
                    originalDataId: [
                        { required: true, message: '原始数据ID（关联数据采集表的id）不能为空', trigger: 'blur' }
                    ],
                    isDeduplicated: [
                        { required: true, message: '是否去重（TRUE为已去重，FALSE为未去重）不能为空', trigger: 'blur' }
                    ],
                    formatType: [
                        { required: true, message: '数据格式类型（如JSON、CSV等）不能为空', trigger: 'blur' }
                    ],
                    formatConversion: [
                        { required: true, message: '是否进行格式转换（TRUE为已转换，FALSE为未转换）不能为空', trigger: 'blur' }
                    ],
                    accuracy: [
                        { required: true, message: '数据准确性（TRUE为准确，FALSE为不准确）不能为空', trigger: 'blur' }
                    ],
                    consistency: [
                        { required: true, message: '数据一致性（TRUE为一致，FALSE为不一致）不能为空', trigger: 'blur' }
                    ],
                    cleaningTime: [
                        { required: true, message: '数据清洗时间不能为空', trigger: 'blur' }
                    ],
                    createTime: [
                        { required: true, message: '记录创建时间不能为空', trigger: 'blur' }
                    ],
                    updateTime: [
                        { required: true, message: '记录更新时间不能为空', trigger: 'blur' }
                    ],
                    cleanedData: [
                        { required: true, message: '清洗后的数据内容不能为空', trigger: 'blur' }
                    ],
                }
            }
        },
        methods: {
            init (id) {
                this.dataForm.orderId = id || 0
                this.visible = true
                this.$nextTick(() => {
                    this.$refs['dataForm'].resetFields()
                    this.dataForm.orderId = id || 0
                    if (this.dataForm.orderId) {
                        this.$http({
                            url: this.$http.adornUrl(`/app/AppDataCleaning/info/\\$\\{this.dataForm.orderId}`),
                            method: 'get',
                            params: this.$http.adornParams()
                        }).then(({data}) => {
                            if (data && data.code === 0) {
                                this.dataForm = data.appdatacleaning
                            }
                        })
                    }
                })
            },
            // 表单提交
            dataFormSubmit () {
                this.$refs['dataForm'].validate((valid) => {
                    if (valid) {
                        this.$http({
                            url: this.$http.adornUrl(`/app/AppDataCleaning/\\$\\{!this.dataForm.orderId ? 'save' : 'update'}`),
                            method: 'post',
                            data: this.$http.adornData(this.dataForm)
                        }).then(({data}) => {
                            if (data && data.code === 0) {
                                this.$message({
                                    message: '操作成功',
                                    type: 'success',
                                    duration: 1500,
                                    onClose: () => {
                                        this.visible = false
                                        this.$emit('refreshDataList')
                                    }
                                })
                            } else {
                                this.$message.error(data.msg)
                            }
                        })
                    }
                })
            }
        }
    }
</script>